import {loginApi} from '@/api/api_chatSocket/chatSocket_Api';
import {MD5, toView} from '@/utils/utils';

// 进行登录操作，并存储返回的token和过期时间（是为了自动获取新token）和账户
export const login = async (account: string, password: string): Promise<void> => {
  const loginResult = await loginApi(account, MD5(password));
  if (!loginResult) return;
  localStorage['token'] = loginResult.data.msg.token;
  localStorage['tokenExpireTime'] = new Date().getTime() + 72*60*60*1000;
  localStorage['account'] = account;
  ElMessage.success(loginResult.data.msg.msg);
  toView('ChatView2');
};
